import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Test {
    public static void main1(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("abc",4);//放入元素
        treeMap.put("hello",3);
        //（k,val）k应该是可以比较的。否则会报错
        treeMap.put("the",8);
        System.out.println(treeMap);//打印treeMap
        Integer val = treeMap.get("hello");
        System.out.println(val);
        Integer val1 = treeMap.getOrDefault("hello12",100);
        //返回指定的key的value，否则则返回指定值
        System.out.println(val1);
        Set<String> keySet = treeMap.keySet();
        //获取包含所有k的值的集合
        System.out.println(keySet);
        System.out.println("=============");
        Set<Map.Entry<String,Integer>> set = treeMap.entrySet();
        for (Map.Entry<String,Integer> entry:set){
            System.out.println("key:"+entry.getKey() + "entry:"+entry.getValue());
        }
    }

    public static void main(String[] args) {
        Set<String> set1 = new TreeSet<>();
        set1.add("hello");
        set1.add("abc");
        set1.add("the");
        //set1.add("hello");
        System.out.println(set1);//只会打印一个hello
    }

}
